import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-04-07
 * Time: 11:35
 */
public class Dilate {
    public static Mat laplaceEnhance(Mat src) {
        Mat srcClone = src.clone();
//        float[] kernel = {0, 0, 0, -1, 5f, -1, 0, 0, 0};
        float[] kernel = {0, 0, 0, -1, 5f, -1, 0, 0, 0};
        Mat kernelMat = new Mat(3, 3, CvType.CV_32FC1);
        kernelMat.put(0, 0, kernel);
        Imgproc.filter2D(srcClone, srcClone, CvType.CV_8UC3, kernelMat);
        return srcClone;
    }
    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src = Imgcodecs.imread("src2.png");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);
        Mat dst = new Mat();

        Imgproc.erode(src, dst, new Mat());//腐蚀
        HighGui.imshow("dst", dst);
        HighGui.waitKey(0);

        Imgproc.dilate(dst, dst, new Mat());
        HighGui.imshow("dst", dst);//膨胀
        HighGui.waitKey(0);

        Imgproc.GaussianBlur(src, dst, new Size(0, 0), 100, 100);
        Core.addWeighted(src, 1.5, dst, -0.5, 0, dst);

        Mat mat = laplaceEnhance(dst);
        HighGui.imshow("laplace",mat);
        HighGui.waitKey(0);

//        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_OPEN, new Mat(), new Point(-1, -1), 3);//开运算消除噪点
//        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_GRADIENT, new Mat());//梯度型操作，起到显示轮廓的作用
//        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE,new Mat(), new Point(-1, -1), 3);//先腐蚀再膨胀
        //Imgproc.morphologyEx(src, dst, Imgproc.MORPH_BLACKHAT, new Mat());
//        HighGui.imshow("dst", dst);
//        HighGui.waitKey(0);
    }
}
